<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/21
 * Time: 6:14 PM
 */
namespace app\service;

use app\model\Wx;
use extend\wx\Crypt;
use extend\wx\WXBizDataCrypt;
use think\facade\Config;
use think\facade\Log;
use think\Service;
use tool\Curl;
use wx\WxCrypt;
class ImgService
{
    protected static $qrcodeBackCleaningImg;
    protected static $qrcodeBackCheckImg;

    public function __construct()
    {
        $config = Config::get('uploader');
        self::$qrcodeBackCleaningImg = $config['qrcode_back_cleaning_pic'];
        self::$qrcodeBackCheckImg = $config['qrcode_back_check_pic'];
    }


    /*
     * 获取地理信息
     */
    public function getQrcode($qrcode,$type = 1){

        $backImg = $type == 1 ? self::$qrcodeBackCleaningImg : self::$qrcodeBackCheckImg;
        $dst = imagecreatefromstring(file_get_contents($backImg));
        $src = imagecreatefromstring($qrcode);


        imagecopymerge($dst, $src, 394.5,157.8, 0, 0, 789, 789, 100);

        $fileName= md5(rand(0,999));
        $EchoPath=root_path().'public/static/qrcode/'.$fileName.'.png';

        imagepng($dst,$EchoPath);
        imagedestroy($dst);

        $PSize = filesize($EchoPath);
        $picturedata = fread(fopen($EchoPath, "r"), $PSize);

        return $picturedata;
    }
}